package com.tanhua.server.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tanhua.dubbo.server.api.RecommendUserApi;
import com.tanhua.dubbo.server.pojo.RecommendUser;
import com.tanhua.dubbo.server.vo.PageInfo;
import com.tanhua.server.vo.TodayBest;
import org.springframework.stereotype.Service;
/**
 * 负责与dubbo服务进行交互
 */
@Service
public class RecommendUserService {
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    /**
     * 根据用户id查询最佳的小姐姐
     * @param id
     * @return
     */
    public TodayBest queryTodayBest(long id) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(id);
        if (null==recommendUser){
            return null;
        }
        TodayBest todayBest=new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //缘分值
        double score=Math.floor(recommendUser.getScore());//取整
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    /***
     * 查询和用户id匹配的所有的小姐姐
     * @param id
     * @param page
     * @param pagesize
     * @return
     */
    public PageInfo queryRecommendation(long id, Integer page, Integer pagesize) {
       return this.recommendUserApi.queryPageInfo(id, page, pagesize);
    }
}
